package vns.server.domain;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

import vns.shared.ObjectValueDTO;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")

public class ObjectValue {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key id;
	
	@Persistent
	private String value; // khi kiểu là key thì value se chứa id của một object lien quan
	//??? quay lai trang luc nay di ong hoi gi

	@Persistent
	private String objectKey;
	
	@Persistent
	private String propertyKey; // Khi load
	//load cai property len, get cai base string neu no la "key" thi ong phai get them cai objectType ra nua
	// sau do load by id cái objectType đó lên, return ve vay la phai viet ham load tra ve mot cai cho ti
	// ong co y kien gi ko
	//
	public ObjectValue(){}

	public ObjectValue(ObjectValueDTO objectValueDTO){
		this.value=objectValueDTO.getValue();
		this.objectKey=objectValueDTO.getObjectKey();
		this.propertyKey=objectValueDTO.getPropertyKey();
	}
	
	public void updatefromDTO(ObjectValueDTO objectValueDTO){
		this.value=objectValueDTO.getValue();
		this.objectKey=objectValueDTO.getObjectKey();
		this.propertyKey=objectValueDTO.getPropertyKey();
	}
	
	public ObjectValueDTO toDTO(){
		ObjectValueDTO objectValueDTO=new ObjectValueDTO(this.id,this.value,this.objectKey,this.propertyKey);
		return objectValueDTO;
	}
	
	public Key getId(){
		return id;
	}
	
	public String getValue(){
		return value;
	}
	
	public void setValue(String Value){
		this.value=Value;
	}

	public void setObjectKey(String objectKey) {
		this.objectKey = objectKey;
	}

	public String getObjectKey() {
		return objectKey;
	}

	public void setPropertyKey(String propertyKey) {
		this.propertyKey = propertyKey;
	}

	public String getPropertyKey() {
		return propertyKey;
	}
}
